<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>学生添加页面</title>
    <link rel="stylesheet" type="text/css" href="../static/admin/layui2/css/layui.css"/>
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
        <div class="layui-logo"><a href="guanliyuan-main.html" style="color: #009688;font-size: 25px;">管理员主页面</a></div>
        <!-- 头部区域（可配合layui已有的水平导航） -->
        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item"><a class="layui-icon layui-icon-user" style="color:#009688;font-size: 20px;text-align: center;" href="student-login.html">学生登录</a></li>
            <li class="layui-nav-item"><a class="layui-icon layui-icon-logout" style="color: #ff3c00;font-size: 20px;text-align: center;" href="guanliyuan-login.html">退出</a></li>
        </ul>
    </div>

    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
            <ul class="layui-nav layui-nav-tree"  lay-filter="test">
                <li class="layui-nav-item">
                    <a href="javascript:;"><i class="layui-icon layui-icon-username" style="font-size: 24px; color: #009688; margin-right: 16px"></i> 信息管理</a>
                    <dl class="layui-nav-child">
                        <dd><a href="guanliyuan-mimaChange.html"><i class="layui-icon layui-icon-edit" style="font-size: 24px; color: #009688; margin-right: 16px"></i>修改密码</a></dd>
                        <dd><a href="guanliyuan-add.html"><i class="layui-icon layui-icon-add-circle" style="font-size: 24px; color: #009688; margin-right: 16px"></i>添加管理员</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item">
                    <a href="javascript:;"><i class="layui-icon layui-icon-user" style="font-size: 24px; color: #009688; margin-right: 16px"></i>学生管理</a>
                    <dl class="layui-nav-child">
                        <dd><a href="guanliyuan-addstudent.html"><i class="layui-icon layui-icon-add-circle" style="font-size: 24px; color: #009688; margin-right: 16px"></i>添加学生</a></dd>
                        <dd><a href="guanliyuan-deletestudent.html"><i class="layui-icon layui-icon-reduce-circle" style="font-size: 24px; color: #009688; margin-right: 16px"></i>删除学生</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item">
                    <a href="javascript:;"><i class="layui-icon layui-icon-group" style="font-size: 24px; color: #009688; margin-right: 16px ;"></i>校友管理</a>
                    <dl class="layui-nav-child">
                        <dd><a href="guanliyuan-addalumni.html"><i class="layui-icon layui-icon-add-circle" style="font-size: 24px; color: #009688; margin-right: 16px"></i>添加校友</a></dd>
                        <dd><a href="guanliyuan-alumni.html"><i class="layui-icon layui-icon-friends" style="font-size: 24px; color: #009688; margin-right: 16px"></i>校友信息</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item layui-nav-iteme">
                    <a href="javascript:;"><i class="layui-icon layui-icon-rmb" style="font-size: 24px; color: #009688; margin-right: 16px"></i>奖学金管理</a>
                    <dl class="layui-nav-child">
                        <dd><a href="guanliyuan-addscholarship.html" class="layui-this"><i class="layui-icon layui-icon-add-circle" style="font-size: 24px; color: #009688; margin-right: 16px"></i>添加奖学金</a></dd>
                        <dd><a href="guanliyuan-scholarship.html"><i class="layui-icon layui-icon-file" style="font-size: 24px; color: #009688; margin-right: 16px"></i>奖学金信息</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item layui-nav-iteme">
                    <a href="guanliyuan-examine.html"><i class="layui-icon layui-icon-survey" style="font-size: 24px; color: #009688; margin-right: 16px"></i>审批</a>
                </li>
            </ul>
        </div>
    </div>

    <div class="layui-body">
        <div class="layui-anim layui-anim-scale" style="margin-top: 50px;margin-left: 50px;">
            <form class="layui-form layui-form-pane" name="form1" id="form1">
                <div class="layui-form-item">
                    <label class="layui-form-label">奖学金名称</label>
                    <div class="layui-input-inline">
                        <input type="text" name="name" id="name" lay-verify="required" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">赞助人</label>
                    <div class="layui-input-inline">
                        <select name="aid" id="aid" lay-verify="required">
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">启用状态</label>
                    <div class="layui-input-inline state">
                        <input type="radio" name="state" id="open" value="1" title="启用" checked>
                        <input type="radio" name="state" id="close" value="0" title="禁 用">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">开始时间</label>
                    <div class="layui-input-inline">
                        <input type="text" name="startTime" id="startTime" lay-verify="required" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">结束时间</label>
                    <div class="layui-input-inline">
                        <input type="text" name="endTime" id="endTime" lay-verify="required" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">金额</label>
                    <div class="layui-input-inline">
                        <input type="text" name="money" id="money" lay-verify="required" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">名额</label>
                    <div class="layui-input-inline">
                        <input type="text" name="sum" id="sum" lay-verify="required" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">申请要求</label>
                    <div class="layui-input-inline">
                        <textarea name="require" id="require" class="layui-textarea" style="width: 500px"></textarea>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-inline">
                        <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">添加</button>
                    </div>
                </div>
            </form>
        </div>
    </div>

    <div class="layui-footer layui-bg-green">

    </div>
</div>
<script src="../static/admin/layui2/layui.js" type="text/javascript" charset="utf-8"></script>
<script>
    layui.use(['element','form','jquery','layer','laydate'], function(){
        var element = layui.element
        var form = layui.form
        laydate = layui.laydate
        layer = layui.layer
        $ =layui.jquery;

        //执行一个laydate实例
        laydate.render({
            elem: '#startTime' //指定元素
            ,type:'datetime',
            isInitValue: true,
            format: "yyyy-MM-dd HH:mm:ss",
            value:new Date(new Date().toLocaleDateString()),
            done: function(value, data, endData) {
                var endTime = new Date($('#endTime').val()).getTime();
                var startDate = new Date(value).getTime();
                if (endTime < startDate) {
                    layer.msg("结束时间不得小于开始时间!",{icon: 5});
                    value.val(" ")
                }

            }
        });
        laydate.render({
            elem: '#endTime' //指定元素
            ,type:'datetime',
            format: "yyyy-MM-dd HH:mm:ss",
            isInitValue: false,
            value:new Date(),
            done: function(value, date, endData) {
                var startDate = new Date($('#startTime').val()).getTime();
                var endTime = new Date(value).getTime();
                if (endTime < startDate) {
                    layer.msg("结束时间不得小于开始时间!",{icon: 5});
                    value.val(" ");
                }
            }

        });

        $.ajax({
            type: "GET",
            url: "/scholarship/selectAllaid",
            dataType: "json",
            success: function (res) {
                var ops = '<option value=""></option>';
                for (var alumni of res.data) {
                    ops += '<option value="' + alumni.aid + '">' +"("+alumni.aid+")"+ alumni.name+ '</option>';
                }
                $('#aid').html(ops);
                form.render();
            }
        });


        form.render();
        form.on('submit(demo1)',function (data) {
            $.ajax({
                type:"Get",
                url:"/scholarship/addScholarship",
                data:{
                    "name": data.field.name,
                    "aid": data.field.aid,
                    "state":data.field.state,
                    "startTime": data.field.startTime,
                    "endTime":data.field.endTime,
                    "money":data.field.money,
                    "sum":data.field.sum,
                    "require":data.field.require,
                },
                dataType:"json",
                success:function (res) {
                    if (res.flag){
                        layer.msg('添加成功', {icon: 1});
                        setTimeout(function () {
                            window.location.href="guanliyuan-addalumni.html";
                        },1000)
                    }else {
                        layer.msg(res.msg,{icon: 5});
                    }
                }
            })
            return false;
        });
    });
</script>
</body>

</html>